<?php

namespace App\Console\Commands;

use App\Constant\SmsTemplate;
use App\Library\Traits\RepaySmsRemind;
use App\Models\RepayRecord;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;

class RepaySmsCommand extends Command
{
    use RepaySmsRemind;
    /**
     * The name and signature of the console command.
     *
     * @var string
     */

    protected $signature = 'repay:sms {action : overdue}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'RepaySms cron relevant';

    /**
     * The console command action. overdue
     *
     * @var string
     */
    protected $action;


    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->initAction();
        $this->runAction();
    }

    /**
     * Description:逾期发送短信
     * Author:lijiafei
     */
    public function overdue(){
//        foreach (RepayRecord::with(['users'])->where('status','<>',RepayRecord::STATUS_FOUR)->where('pay_off','=',RepayRecord::PAY_OFF_ONE)->where('normal_date','<',Carbon::now()->toDateString())->get() as $record){
//            $real_name = isset($record->users->real_name) ? $record->users->real_name : '';
//            $phone_num = isset($record->users->phone_num) ? $record->users->phone_num : 0;
//            $create_at = isset($record->created_at) ? $record->created_at : '';
//            if($phone_num && $create_at){
//                $month = $create_at->month;
//                $day = $create_at->day;
//                $sendData['name'] = $real_name;  //用户姓名
//                $sendData['month'] = $month; //月份
//                $sendData['day'] = $day; //天
//                SmsTemplate::send(SmsTemplate::TEMPLATE_REPLY_OVERDUE,$phone_num,$sendData);
//            }
//        }
        self::sendOverdueSms();
    }

    /**
     * Description: Initialize command action.
     * Author: Gxs
     */
    protected function initAction()
    {
        $this->action = $this->argument('action');

        if (!in_array($this->action, ['overdue'])) {
            $this->error("Invalid argument '{$this->action}'. Expected 'overdue'.");
            exit(1);
        }
    }

    /**
     * Description: Run action.
     * Author: Gxs
     */
    protected function runAction()
    {
        $this->{$this->action}();
    }

}
